package hello.dao;

import hello.bean.address.Address;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;
import org.springframework.data.rest.core.annotation.RestResource;
import org.springframework.security.access.prepost.PreAuthorize;

import java.util.List;

/**
 * @Description:
 * @Author: m01
 * @Date: created at  2018/12/19  10:24
 * @Modified By:
 */


@RepositoryRestResource(collectionResourceRel = "address", path = "address")
@PreAuthorize("hasRole('ROLE_ADMIN')")
public interface AddressDao extends PagingAndSortingRepository<Address, Long> {


    @RestResource(path = "city", rel = "city")
    public Address findByCity(@Param("city") String city);



    @RestResource(path = "getRoadByCity", rel = "getRoadByCity")
    @Query(value = "select *  from  address a where a.city = :city",nativeQuery = true)
    public List<Address> getRoadByCity(@Param("city") String city);


    @RestResource(path = "getRoadAndCityById", rel = "getRoadAndCityById")
    @Query(value = "select * from  address a where a.id= :id", nativeQuery = true)
    public List<Address> getRoadAndCityById(@Param("id") Long id);




}
